<?php
import( 'de.ceus-media.framework.krypton.core.Logic' );
import( 'classes.model.Server' );
//import( 'de.ceus-media.framework.krypton.core.database.StatementBuilder' );
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
class Logic_Server extends Framework_Krypton_Core_Logic
{
	function addServer( $data, $prefix = "" )
	{
		$data	= $this->removePrefixFromFields( $data, $prefix );
		$this->validateForm( 'administration/server', 'addServer', $data, $prefix );
		$data['created']	= time();
		$model	= new Model_Server();
		return $model->insert( $data );
	}
	
	function editServer( $serverId, $data, $prefix = "" )
	{
		if( !$serverId )
		 	throw new Framework_Krypton_Exception_Logic( 'server_id_missing' );
		$model	= new Model_Server( $serverId );
		if( !$model->exists() )
			throw new Framework_Krypton_Exception_Logic( 'invalid_server_id' );
		$data	= $this->removePrefixFromFields( $data, $prefix );
		$this->validateForm( 'administration/server', 'editServer', $data, $prefix );
		$result	= $model->update( $data );
		if( $result )
			$model->update( array( 'modified' => time() ) );
		return $result;
	}
	
	static function getServerData( $serverId )
	{
		$model	= new Model_Server( $serverId );
		$data	= $model->get();
		if( !$data )
			throw new Framework_Krypton_Exception_Logic( 'invalid_server_id' );
		return $data;
	}
	
	static function getServerDescription( $serverId )
	{
		$data	= self::getServerData( $serverId );
		return $data['description'];
	}
	
	static function getServerList( $assoc = false )
	{
		$projects	= array();
		$model	= new Model_Server();
		$list	= $model->find();
		return $list;
	}
	
	static function getServers( $assoc = false )
	{
		$servers	= array();
		$model	= new Model_Server();
		$list	= $model->find();
		foreach( $list as $entry )
			$servers[$entry['server_id']]	= $entry['title'];
		return $servers;
	}
	
	static function getServerTitle( $serverId )
	{
		$data	= self::getServerData( $serverId );
		return $data['title'];
	}
}
?>
